<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var a = "1111";
        var b = "1111";

        var addBinary = function (a, b) {
            // return (BigInt(`0b${a}`, 2) + BigInt(`0b${b}`, 2)).toString(2);
            a.length >= b.length ? b = b.padStart(a.length, '0') : a = a.padStart(b.length, '0');
            var next = 0;
            var arr = []
            for (var i = a.length - 1, j = b.length - 1; i >= 0, j >= 0; i--, j--) {
                var sum = Number(a[i]) + Number(b[j]) + next;
                if (sum < 2) {
                    arr.push(sum)
                    next = 0
                } else {
                    arr.push(sum%2)
                    next = 1;
                } 
            }
            if (next != 0) {
                arr.push(next)
            }
            return arr.reverse().join("")
        };
        console.log(addBinary(a, b));
    </script>
</body>

</html>